package com.example.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;

import com.example.common.annotation.DataFilter;
import com.example.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.modules.sys.entity.TemperatureEntity;
import com.example.modules.sys.service.TemperatureService;
import com.example.common.utils.PageUtils;
import com.example.common.utils.R;



/**
 * 体温
 *
 * @author 
 * @email 
 * @date 2020-06-05 18:48:44
 */
@RestController
@RequestMapping("sys/temperature")
public class TemperatureController {
    @Autowired
    private TemperatureService temperatureService;

    /**
     * 列表
     */
    @DataFilter(subDept = false, user = true)
    @RequestMapping("/list")
    @RequiresPermissions("sys:temperature:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = temperatureService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @DataFilter(subDept = true, user = true)
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:temperature:info")
    public R info(@PathVariable("id") Long id){
        TemperatureEntity temperature = temperatureService.getById(id);

        return R.ok().put("temperature", temperature);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:temperature:save")
    public R save(@RequestBody TemperatureEntity temperature){
        temperatureService.save(temperature);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:temperature:update")
    public R update(@RequestBody TemperatureEntity temperature){
        ValidatorUtils.validateEntity(temperature);
        temperatureService.updateById(temperature);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:temperature:delete")
    public R delete(@RequestBody Long[] ids){
        temperatureService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
